package com.henry.chatkit.demo

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.henry.chatkit.ChatKit
import com.henry.chatkit.MessageStatus
import com.henry.chatkit.chat.ChatLayout
import com.henry.chatkit.messages.*
import com.henry.chatkit.utils.BackgroundTasks


class ChatActivity : AppCompatActivity() {

    private val chatLayout: ChatLayout by lazy { findViewById(R.id.chat_layout) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_chat)

        ChatKit.instance.initKit(this)

        initView()
        loadData()

        val helper = ChatLayoutHelper(this)
        helper.customizeChatLayout(chatLayout)
    }

    private fun initView() {
        chatLayout.initDefault()



    }

    fun loadData() {
        val msg = MessageExt.buildTextMessage("1")

        val msg2 = MessageExt.buildTextMessage("我的审美呀")
        msg2.isSelf = false
        val msg21 = MessageExt.buildTextMessage("我的审美呀111")
        msg21.isSelf = false

        val msg22 = MessageExt.buildTextMessage("2")
        val msg23 = MessageExt.buildTextMessage("3")

        val msg3 = MessageExt.buildTextMessage("事务局近似数据睡觉死就死将死就死时间段金丝低筋粉is京东方事务局近似数据睡觉死就死将死就死时间段金丝低筋粉is京东方事务局近似数据睡觉死就死将死就死时间段金丝低筋粉is京东方")
        val msg4 = MessageExt.buildImageMessage("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg", 70, 70)
        msg4.status = MessageStatus.SEND_FAIL
        val msg41 = MessageExt.buildImageMessage("https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=366763321,1800567094&fm=26&gp=0.jpg")
        msg41.isSelf = false

        val msg5 = MessageExt.buildAudioMessage(
            "/storage/emulated/0/Android/data/com.henry.chatkit/files/voice/e1bb6fcb7680e0d97cc0631526fc7254.m4a",
            10
        )
        val msg51 = MessageExt.buildAudioMessage("", 60)
        val msg52 = MessageExt.buildAudioMessage("", 1)
        val msg53 = MessageExt.buildAudioMessage("", 2)
        val msg54 = MessageExt.buildAudioMessage("", 40)
        val msg55 = MessageExt.buildAudioMessage(
            "/storage/emulated/0/Android/data/com.henry.chatkit/files/voice/e1bb6fcb7680e0d97cc0631526fc7254.m4a",
            3
        )

        val msg6 = MessageExt.buildFileMessage("")

        val customMessage = CustomMessage()
        customMessage.customType = 0
        val msg7 = MessageExt.buildCustomMessage(customMessage)

        val customMessage1 = CustomMessage()
        customMessage1.customType = 1
        val msg71 = MessageExt.buildCustomMessage(customMessage1)
        msg71.isSelf = false

        val msg8 = MessageExt.buildSystemMessage("system");

        msg51.isSelf = false

//        val list = mutableListOf(
//                msg7,
//        )
        val list = mutableListOf(
            msg,
            msg2, msg21, msg22, msg23,
            msg3,
            msg4, msg41, msg5, msg51, msg52, msg53, msg54, msg55,
            msg6,
            msg7, msg71,
            msg8,
        )

        chatLayout.reloadData(list)
    }

}